﻿using UnityEngine;
using System.Collections;

public enum InputType{
	NOTHING,
	START_TALK,	//对话
	PICK_UP,	//拾取
	SHOW_BACKPACK,	//显示背包
	SHOW_PREVIEW_ITEM,	//显示上一个物品
	SHOW_NEXT_ITEM,	//显示下一个物品
	CONFIRM,	//确认
	OPEN_DOOR,	//开门
	WRITING,	//书写
	SPECIAL_BEHAVIOUR,	//特殊行为
	CLICK_BUTTON,
	TAKE_PHOTO,
	RIGHT_CONFIRM,	//右手的扳机
	LEFT_CONFIRM	//左手的扳机
};
public class MyInput : MonoBehaviour {

	public static bool GetInputOfType(InputType inputType){
		switch (inputType) {
		case InputType.NOTHING:
			return true;
			break;
		case InputType.START_TALK:
			return Input.GetButtonDown ("StartTalk");
			break;
		case InputType.PICK_UP:
			return Input.GetButtonDown ("PickUp");
			break;
		case InputType.SHOW_BACKPACK:
			return Input.GetButtonDown ("ShowBackpack");
			break;
		case InputType.SHOW_PREVIEW_ITEM:
			return Input.GetKeyDown (KeyCode.N);
			break;
		case InputType.SHOW_NEXT_ITEM:
			return Input.GetKeyDown (KeyCode.M);
			break;
		case InputType.CONFIRM:
			//return Input.GetButtonDown ("Confirm");
			return Input.GetMouseButtonDown(0);
			break;
		case InputType.OPEN_DOOR:
			return Input.GetButtonDown ("OpenDoor");
			break;
		case InputType.WRITING:
			return Input.GetButton ("Special_Behaviour");
			break;
		case InputType.SPECIAL_BEHAVIOUR:
			return Input.GetButtonDown ("Special_Behaviour");
			break;
		case InputType.CLICK_BUTTON:
			return Input.GetMouseButtonDown (0);
			break;
		case InputType.TAKE_PHOTO:
			return Input.GetMouseButtonDown (1);
			break;
		case InputType.LEFT_CONFIRM:
			return Input.GetKeyDown (KeyCode.B);
			break;
		case InputType.RIGHT_CONFIRM:
			return Input.GetKeyDown (KeyCode.M);
			break;
		default:
			return false;
			break;
		}
		return false;
	}

	/// <summary>
	/// 获取玩家的移动方向
	/// </summary>
	/// <returns>The player walk.</returns>
	/// <param name="speed">Speed.</param>
	public static Vector2 GetPlayerWalk(float speed = 1f){
		float x = GetDirection (KeyCode.D, KeyCode.A);
		float y = GetDirection (KeyCode.W, KeyCode.S);
		Vector2 walkDir = new Vector2 (x, y);
		if (walkDir.sqrMagnitude > 0f) {
			walkDir.Normalize ();
		}
		return walkDir * speed;
	}

	/// <summary>
	/// 获取左手的移动
	/// </summary>
	/// <returns>The left hand move.</returns>
	/// <param name="speed">Speed.</param>
	public static Vector3 GetLeftHandMove(float speed = 1f){
		float x = GetDirection (KeyCode.J, KeyCode.G);
		float z = GetDirection (KeyCode.Y, KeyCode.H);
		float y = GetDirection (KeyCode.U, KeyCode.T);
		Vector3 moveDir = new Vector3 (x, y, z);
		if (moveDir.sqrMagnitude > 0f) {
			moveDir.Normalize ();
		}
		return moveDir * speed;
	}

	/// <summary>
	/// 获取右手的移动
	/// </summary>
	/// <returns>The left hand move.</returns>
	/// <param name="speed">Speed.</param>
	public static Vector3 GetRightHandMove(float speed = 1f){
		float x = GetDirection (KeyCode.Semicolon, KeyCode.K);
		float z = GetDirection (KeyCode.O, KeyCode.L);
		float y = GetDirection (KeyCode.P, KeyCode.I);
		Vector3 moveDir = new Vector3 (x, y, z);
		if (moveDir.sqrMagnitude > 0f) {
			moveDir.Normalize ();
		}
		return moveDir * speed;
	}


	static float GetDirection(KeyCode positiveKey, KeyCode negativeKey){
		float dir = 0f;
		if (Input.GetKey (positiveKey)) {
			if (!Input.GetKey (negativeKey)) {
				dir = 1f;
			}
		} else if (Input.GetKey (negativeKey)) {
			dir = -1f;
		}
		return dir;
	}
}
